<div>
<h2><?php  __('Müzik');?></h2>
<div class="viewimage">
<?php echo $this->Html->image($music['Product']['image'],array('class'=>'viewresim'));?>
</div>
<div class="viewinfo">
<div class="viewname">
<?php echo $music['Product']['name'];?>
</div>
<div class="viewproducer">
<?php echo $this->Html->link($music['Producer']['full_name'], array('controller' => 'producers', 'action' => 'view', $music['Producer']['id'])); ?>
</div>
<div class="viewscore">
<b>Puan : </b><span id="product_score"><?php echo $music['Product']['score'];?></span> / 5<br/>
<?php if($user): ?>
	<div id="star_rate">
	<form id="ScoreAddForm" action="/bookstore/scores/add" method="POST">
	<input type="hidden" value="POST" name="_method">
	<input type="hidden" value="<?php echo $music['Product']['id'];?>" name="data[Score][product_id]" />
	<input type="hidden" value="<?php echo $user['id'];?>" name="data[Score][user_id]" />
	<select name="data[Score][score]" class="rating" id="starating">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
	</select>
	</form>
	</div>
<?php endif; ?>
</div>
<div class="addcartbutton">
<?php echo $this->Form->button('<span class="rightarrow icon"></span>Sepete Ekle',array('class'=>'add2cart button pill','onclick'=>'add2cart('.$music['Product']['id'].')'));?>
</div>
<?php if(!empty($music['Product']['pages'])):?>
<div class="inside_book">
	<a href="/bookstore/products/pageflip/<?php echo $music['Product']['id']; ?>" class="button pill" target="_blank"><span class="book icon"></span>İç Sayfalar</a>
</div>
<?php endif;?>
</div>
<div class="viewdesc">
<b>Türü : </b><?php echo $music['Product']['genre'];?><br/><br/>
<b>Tanıtım :</b><br/><br/><?php echo $music['Product']['description'];?>
</div>
</div>
<br/>
<div class="related comment_container" id="comment_container">
<div id="comments">
<?php foreach ($music['Comment'] as $comment): ?>
<div class="commentbox">
<?php echo $comment['Comment']['comment'];?>
</div>
<div class="commentfooter"><?php echo $comment['User']['username'].", ".$this->Time->format($format = 'd.m.Y H:i', $comment['Comment']['created']); ?></div>
<?php endforeach; ?>
</div>
<?php 
if($user) { 
	echo $this->Form->button('<span class="comment icon"></span>Yorum Ekle', array('class'=>'button', 'id'=>'addcommentbutton'));
?>
<script type="text/javascript">
$(document).ready(function(){
	//$('#savecommentbutton').attr('type','');
	$('#addcommentbutton').click(function(){
		$('#addcommentform').slideToggle('normal');
	});
	
	$('#savecommentbutton').click(function(){
		$.ajax({
			type: 'POST',
			url: '/bookstore/comments/add',
			data: 'data=' + $('#CommentAddForm').serialize(),
			dataType:'json',
			success: function(data) {
				$('#comments').append('<div class="commentbox">' + data.Comment.comment + '</div>' + 
										'<div class="commentfooter"><?php echo $user['username'];?>, ' + data.Comment.created + '</div>'
				);
			},
			error: function(xhr, textStatus, errorThrown){
			       alert('Bu ürüne daha önceden yorum yapmıştınız. Her ürün için sadece bir yorum kabul edilir.');
			}		
		});
	});
	$(".rating").rating({showCancel: false,})
	$('#starating').change(function(){
		//$(this).attr('disabled', 'disabled');
		//$(".rating").rating({showCancel: false,})
		$.ajax({
			type: 'POST',
			url: '/bookstore/scores/add',
			data: 'data=' + $('#ScoreAddForm').serialize(),
			dataType:'json',
			success: function(data) {
				$('#product_score').html(data.Product.score);
			},
			error: function(xhr, textStatus, errorThrown){
			       alert('Bu ürünü daha önce puanlamıştınız. Her ürün için sadece bir kere puan verebilirsiniz.');
			}
		});
	});	
});
</script>

<div id="addcommentform">
<?php
echo $this->Form->create('Comment',array('controller'=>'comments', 'action'=>'add', 'onsubmit'=>'return false;'));
echo $this->Form->input('product_id', array('value'=>$music['Product']['id'], 'type'=>'hidden'));
echo $this->Form->input('user_id', array('value'=>$user['id'], 'type'=>'hidden'));
echo $this->Form->input('comment');
echo $this->Form->button('<span class="check icon"></span>Kaydet',array('type'=>'submit','id'=>'savecommentbutton','class'=>'button'));
echo $this->Form->end();
?>
</div>
<?php
} else {
	echo "Yorum yazabilmeniz için giriş yapmanız gerekmektedir."; 
}
?>
<br><br>
</div>
<?php if(!empty($related_music)):?>
<div class="related_products">
<h3><center><?php  __('İlişkili Ürünler');?></center></h3>
<?php foreach ($related_music as $item):?>
<div class="product">
<?php 
echo $this->Html->div('product_name', $this->Html->link($item['Product']['name'], array('controller'=>'musics', 'action'=>'view', $item['Product']['id'])));
echo $this->Html->div('urunresim', $this->Html->image($item['Product']['image'], array('alt'=>$item['Product']['name'], 'class'=>'urunresim', 'url'=>array('controller'=>'musics', 'action'=>'view', $item['Product']['id'])))); 
echo $this->Html->div('producer' ,$item['Producer']['full_name']);
echo $this->Html->div('price' ,$item['Product']['price']." TL");
echo $this->Form->button('<span class="rightarrow icon"></span>Sepete Ekle',array('class'=>'add2cart button pill','onclick'=>'add2cart('.$item['Product']['id'].')'));?>
</div>
<?php endforeach;?>
</div>
<?php endif;?>
<?php if(!empty($other_musics)):?>
<div class="producers_other">
<h3><center><?php  __('Sanatçının Diğer Eserleri');?></center></h3>
<?php foreach ($other_musics as $item):?>
<div class="product">
<?php 
echo $this->Html->div('product_name', $this->Html->link($item['Product']['name'], array('controller'=>'books', 'action'=>'view', $item['Product']['id'])));
echo $this->Html->div('urunresim', $this->Html->image($item['Product']['image'], array('alt'=>$item['Product']['name'], 'class'=>'urunresim', 'url'=>array('controller'=>'books', 'action'=>'view', $item['Product']['id'])))); 
echo $this->Html->div('producer' ,$item['Producer']['full_name']);
echo $this->Html->div('price' ,$item['Product']['price']." TL");
echo $this->Form->button('<span class="rightarrow icon"></span>Sepete Ekle',array('class'=>'add2cart button pill','onclick'=>'add2cart('.$item['Product']['id'].')'));?>
</div>
<?php endforeach;?>
</div>
<?php endif;?>